<meta charset="utf-8" />
<html>
<head>
<title></title>
<style>
	body{
		width: 100%;
		font-size: 16px;
		font-family: "微软雅黑";
	}
	div.content{
		height: 400px;
	}
	div.page{
		text-align: center;
		margin-top: 10px;
	}
	div.page a{
		border: #aaaadd 1px solid;
		text-decoration: none;
		padding: 2px 5px;
		margin: 2px;
	}
	div.page span.current{
		border:#0000FF 1px solid;
		background-color:#0066CC ;
		color: white;
		padding: 4px 6px 4px 6px;
		margin: 2px;
		font-weight:bold ;
		
		
	}
	div.page span.disable{
		border: #eee 1px solid;
		padding: 2px 5px;
		margin: 2px;
		color: #E1E1E8;
		
	}
	div.page form{
		display: inline;
	}
</style>
</head>
<body>
<?php
include("./conn/conn.php");
//$page=$_GET['p'];
$page=isset($_GET["page"])?$_GET["page"]:1;
$pageSize=10;
$showPage=5; 
$sql="select * from tb_news limit ".($page-1)*$pageSize.",{$pageSize}";

echo '<div class="content">';
echo '<table border="1"  cellpadding="5" cellspacing="0" align="center" width="500">
	<tr>
		<td colspan="7" align="center">茂职院学生管理系统</td>
	</tr>
	<tr>
		<th>ID</th><th>NAME</th>
	</tr>
';
//MYSQL显示数据
$result=mysqli_query($link, $sql);
while ($rows = mysqli_fetch_array($result)) {
	echo '<tr>
		<td>' . $rows['no'] . '</td>
		<td>' . $rows['title'] . '</td>';
}

	echo "</table>";
	echo "</div>";
 //计算总页数
$total_sql="SELECT COUNT(*) FROM tb_news";
$result2=mysqli_query($link,$total_sql);
    $total_result=mysqli_fetch_array($result2);
    $total=$total_result[0];
    $total_pages=ceil($total/$pageSize);
	mysqli_close($link);	
	
$page_banner="<div class='page'>";


//首页，上一页页面显示
if($page>1){
        $page_banner.= "<a href='".$_SERVER['PHP_SELF']."?p=1'>首页</a>";
        $page_banner.= "<a href='".$_SERVER['PHP_SELF']."?p=".($page-1)."'><上一页</a>";
    }else{
        $page_banner.="<span class='disable'>首页</span>";
        $page_banner.="<span class='disable'>上一页</span>";
    }
//偏移量
    $pageoffset=($showPage-1)/2;
//计算偏移量 显示前面页数的...
$start=1;
$end=$total_pages;
//首部省略
if($total_pages>$showPage){
	if($page>$pageoffset+1){
		$page_banner.="...";
	}
	if($page>$pageoffset){
		$start=$page-$pageoffset;
		$end=$total_pages>$page+$pageoffset?$page+$pageoffset:$total_pages;
		
	}else{
		$start=1;
		$end=$total_pages>$showPage?$showPage:$total_pages;
	}
	if($page+$pageoffset>$total_pages){
		$start=$start-($page+$pageoffset-$end);
		
	}
	
}

//循环显示页数
for($i=$start;$i<=$end;$i++){
	if($page==$i){
		$page_banner.="<span class='current'>{$i}</span>";
	}else{
	$page_banner.="<a href='".$_SERVER['PHP_SELF']."?page=".$i."'>{$i}</a>";
	}
}
//尾部省略
if($total_pages>$showPage&&$total_pages>$page+$pageoffset){
	$page_banner.="...";
}

	
//下一页，尾页的页面显示
if($page<$total_pages){
        $page_banner.="<a href='".$_SERVER['PHP_SELF']."?p=".($page+1)."'>下一页></a>";
        $page_banner.= "<a href='".$_SERVER['PHP_SELF']."?p=".($total_pages)."'>尾页</a>";
    }else{
        $page_banner.="<span class='disable'>下一页</span>";
        $page_banner.="<span class='disable'>尾页</span>";
    }	

$page_banner.="共{$total_pages}页,";
$page_banner.='<form action="fenye4.php" method="get" align="center" >
	到第<input type="text" size="1" name="p" />页
	<input type="submit" value="确定" />
</form></div>';
echo $page_banner;
?>
</body>
</html>